import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory("/backend/"),
  routes: [
    {
      path: '/',
      redirect: '/totalData',
      meta: {
        keepAlive: false
      }
    },
    {
      path: '/main',
      name: 'main',
      component: () => import('@/views/Main.vue'),
      meta: {
        keepAlive: false
      },
      children: [
        {
          path: '/totalData',
          name: 'totalData',
          component: () => import('@/views/TotalData.vue'),
          meta: {
            keepAlive: false,
            route: [{ name: '数据总览' }]
          }
        },
        {
          path: '/user',
          name: 'user',
          component: () => import('@/views/User.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '用户管理' }]
          }
        },
        {
          path: '/userOnline',
          name: 'userOnline',
          component: () => import('@/views/UserOnline.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '在线列表' }]
          }
        },
        {
          path: '/UserMonitor',
          name: 'UserMonitor',
          component: () => import('@/views/userCtl/UserMonitor.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '用户监控' }]
          }
        },
        {
          path: '/UserLog',
          name: 'UserLog',
          component: () => import('@/views/userCtl/UserLog.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '用户日志' }]
          }
        },
        {
          path: '/UserGameList',
          name: 'UserGameList',
          component: () => import('@/views/UserGameList.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '在线列表' }]
          }
        },
        
        {
          path: '/subUser',
          name: 'subUser',
          component: () => import('@/views/SubUser.vue'),
          meta: {
            keepAlive: false,
            route: [{ name: '用户管理' }, { name: '下级列表' }]
          }
        },
        {
          path: '/fundSetting',
          name: 'fundSetting',
          component: () => import('@/views/FundSetting.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '资金管理' }, { name: '资金设置' }]
          }
        },
        {
          path: '/deposit',
          name: 'deposit',
          component: () => import('@/views/Deposit.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '资金管理' }, { name: '充值记录' }]
          }
        },
        {
          path: '/withdraw',
          name: 'withdraw',
          component: () => import('@/views/Withdraw.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '资金管理' }, { name: '提现记录' }]
          }
        },
        {
          path: '/activity',
          name: 'activity',
          component: () => import('@/views/Activity.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '活动设置' }]
          }
        },
        {
          path: '/gameCompany',
          name: 'gameCompany',
          component: () => import('@/views/GameCompany.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }, { name: '游戏公司' }]
          }
        },
        {
          path: '/gameList',
          name: 'gameList',
          component: () => import('@/views/GameList.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }, { name: '游戏列表' }]
          }
        },
        {
          path: '/gameList_me',
          name: 'gameList_me',
          component: () => import('@/views/GameList_me.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }, { name: '游戏列表' }]
          }
        },
        {
          path: '/FixCfg',
          name: 'FixCfg',
          component: () => import('@/views/gameCtl/FixCfg.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }, { name: '补偿配置' }]
          }
        },
        {
          path: '/GameCfg',
          name: 'GameCfg',
          component: () => import('@/views/GameCfg.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }]
          }
        },
        {
          path: '/ChangeCode',
          name: 'ChangeCode',
          component: () => import('@/views/ChangeCode.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '活动管理' }, { name: '兑换码' }]
          }
        },
        {
          path: '/gameStock',
          name: 'gameStock',
          component: () => import('@/views/GameStock.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '游戏管理' }, { name: '游戏列表' }]
          }
        },
        {
          path: '/msgManage',
          name: 'msgManage',
          component: () => import('@/views/MsgManage.vue'),
          meta: {
            keepAlive: true,
            route: [{ name: '系统设置' }, { name: '短信设置' }]
          }
        },
        {
          path: '/warning',
          name: 'warning',
          component: () => import("@/views/Warning.vue"),
          meta: {
            keepAlive: true,
            route: [{ name: '系统设置' }, { name: '预警设置' }]
          }
        },
        {
          path: '/SubAdmin',
          name: 'SubAdmin',
          component: () => import("@/views/SubAdmin.vue"),
          meta: {
            keepAlive: true,
            route: [{ name: '系统设置' }, { name: '代理列表' }]
          }
        },
        {
          path: '/UserReg',
          name: 'UserReg',
          component: () => import("@/views/userCtl/UserReg.vue"),
          meta: {
            keepAlive: true,
            route: [{ name: '系统设置' }, { name: '注册管理' }]
          }
        }
        // {
        //   path: '/message',
        //   name: 'message',
        //   component: () => import('@/views/Message.vue'),
        //   meta: {
        //     keepAlive: false,
        //     route: [{ name: '消息管理' }]
        //   }
        // },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login.vue'),
      meta: {
        keepAlive: false,
      }
    },
  ]
})

router.beforeEach((to, from, next) => {
  if (to.name != 'login' && !localStorage.getItem('token')) {
    next('/login')
  } else {
    if (to.meta.route)
      document.title = to.meta.route[to.meta.route.length - 1].name
    next()
  }
})

export default router
